package com.axend.aerosense.base.utils;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 线程池
 */
public class ThreadPoolUtils {

    private ThreadPoolExecutor threadPoolExecutor;

    private static class Holder{
        private static final ThreadPoolUtils INSTANCE = new ThreadPoolUtils();
    }

    private ThreadPoolUtils(){
        init();
    }

    private void init(){
        threadPoolExecutor = new ThreadPoolExecutor(
                4,
                8,
                1,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(10),
                new ThreadPoolExecutor.DiscardOldestPolicy()
        );
    }

    public static ThreadPoolUtils getInstance(){
        return Holder.INSTANCE;
    }

    public void execute(Runnable runnable){
        threadPoolExecutor.execute(runnable);
    }

}
